/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.security.logging;

import com.google.common.collect.Maps;

import java.util.Map;

//import org.apache.solr.common.util.SimpleOrderedMap;

public abstract class LoggerInfo implements Comparable<LoggerInfo> {
    public static final String ROOT_NAME = "root";

    protected final String name;
    protected String level;

    public LoggerInfo(String name) {
        this.name = name;
    }

    public String getLevel() {
        return this.level;
    }

    public String getName() {
        return this.name;
    }

    public abstract boolean isSet();

//    public SimpleOrderedMap<?> getInfo() {
    public Map<String, ?> getInfo() {
        /*
        SimpleOrderedMap info = new SimpleOrderedMap();
        info.add("name", getName());
        info.add("level", getLevel());
        info.add("set", Boolean.valueOf(isSet()));
        */

        Map<String, Object> info = Maps.newHashMap();
        info.put("name", getName());
        info.put("level", getLevel());
        info.put("set", Boolean.valueOf(isSet()));
        return info;
    }

    public int compareTo(LoggerInfo other) {
        if (equals(other)) {
            return 0;
        }
        String tN = getName();
        String oN = other.getName();

        if (ROOT_NAME.equals(tN)) {
            return -1;
        }

        if (ROOT_NAME.equals(oN)) {
            return 1;
        }

        return tN.compareTo(oN);
    }
}